package com.java.simple.smallspring.jdbc.support;

import com.java.simple.smallspring.beans.factory.InitializingBean;
import lombok.Getter;
import lombok.Setter;

import javax.sql.DataSource;
import java.util.Objects;

/**
 * @author zhoujunlin
 * @date 2022年11月19日 21:53
 * @desc jdbc存取
 */
public class JdbcAccessor implements InitializingBean {

    @Getter
    @Setter
    private DataSource dataSource;

    public DataSource obtainDataSource() {
        return getDataSource();
    }

    @Override
    public void afterPropertiesSet() {
        if (Objects.isNull(getDataSource())) {
            throw new IllegalArgumentException("Property 'datasource' is required");
        }
    }
}
